<html>
<head><meta charset="utf-8"><title>Work on &quot;Create from usage&quot; quickfixes · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html">Work on &quot;Create from usage&quot; quickfixes</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="200449550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Work%20on%20%22Create%20from%20usage%22%20quickfixes/near/200449550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html#200449550">(Jun 10 2020 at 17:34)</a>:</h4>
<p>Hi everyone, I'm slowly starting to work on <a href="https://github.com/rust-analyzer/rust-analyzer/issues/4563">https://github.com/rust-analyzer/rust-analyzer/issues/4563</a><br>
I'm stuck on a (hopefully) trivial issue again, what can I do when a test fails with the following?<br>
This time I checked that the test fixture doesn't have syntax errors etc ;)</p>
<div class="codehilite"><pre><span></span><code>---- diagnostics::tests::test_add_field_from_usage stdout ----
[crates/ra_ide/src/diagnostics.rs:132] record_lit.path().unwrap() = Path {
    syntax: PATH@41..44
      PATH_SEGMENT@41..44
        NAME_REF@41..44
          IDENT@41..44 &quot;Foo&quot;
    ,
}
thread &#39;diagnostics::tests::test_add_field_from_usage&#39; panicked at &#39;

Failed to lookup PATH@41..44 in this Semantics.
Make sure to use only query nodes, derived from this instance of Semantics.
root node:   SOURCE_FILE@0..158
known nodes:
</code></pre></div>


<p>The test looks like this:</p>
<div class="codehilite"><pre><span></span><code>    #[test]
    fn test_add_field_from_usage() {
        check_apply_diagnostic_fix(
            r&quot;
            fn main() {
                Foo { bar: 3, baz: false};
            }
            struct Foo {
                bar: i32
            }
            &quot;,
            r&quot;
            fn main() {
                Foo { bar: 3, baz: false};
            }
            struct Foo {
                bar: i32,
                baz: bool
            }
            &quot;,
        )
    }
</code></pre></div>



<a name="200452628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Work%20on%20%22Create%20from%20usage%22%20quickfixes/near/200452628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html#200452628">(Jun 10 2020 at 17:56)</a>:</h4>
<p>I think that means you've got a bug in your code? basically, as the message says, you can only pass syntax nodes to <code>Semantics</code> if you derived them from a node you got from it. I'd check the backtrace</p>



<a name="200456514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Work%20on%20%22Create%20from%20usage%22%20quickfixes/near/200456514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html#200456514">(Jun 10 2020 at 18:25)</a>:</h4>
<p>hmm, i got the syntax from the same <code>AstDatabase</code> which the <code>Semantics</code> is based on. i'm gonna check the backtrace though.</p>



<a name="200457441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Work%20on%20%22Create%20from%20usage%22%20quickfixes/near/200457441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html#200457441">(Jun 10 2020 at 18:32)</a>:</h4>
<p>that's not enough, you need to get it from a <code>parse</code> / <code>expand</code> / etc. call on the same <code>Semantics</code> object</p>



<a name="200458491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Work%20on%20%22Create%20from%20usage%22%20quickfixes/near/200458491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html#200458491">(Jun 10 2020 at 18:41)</a>:</h4>
<p>aw man, and <code>Semantics::parse</code> doesn't return the syntax errors which the <code>diagnostics</code> function uses :c</p>



<a name="200459333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Work%20on%20%22Create%20from%20usage%22%20quickfixes/near/200459333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html#200459333">(Jun 10 2020 at 18:47)</a>:</h4>
<p>if you're getting the syntax node via <code>AstDiagnostic::ast</code>, you could add a method to <code>Semantics</code> that does the same thing. you just need to call <code>cache</code> with the root node and the correct <code>HirFileId</code> (which you can get from the diagnostic, I think)</p>



<a name="200465720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Work%20on%20%22Create%20from%20usage%22%20quickfixes/near/200465720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Work.20on.20.22Create.20from.20usage.22.20quickfixes.html#200465720">(Jun 10 2020 at 19:35)</a>:</h4>
<p>Ok, I hoped I wouldn't have to add a new method to <code>Semantics</code>, but if that's necessary <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span><br>
Thanks for the support :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>